home *** CD-ROM | disk | FTP | other *** search
/ Video Toaster 4.2 / Video Toaster v4.2.iso / arexx / modeler / cage.lwm < prev    next >
Text File  |  1993-12-13  |  3KB  |  129 lines

  1. /* CMD: Spline Cage
  2.  *
  3.  * Generate a cylindrical spline cage for starting point in spline modeling.
  4.  */
  5.  
  6.  
  7. call addlib "LWModelerARexx.port", 0
  8. MATHLIB="rexxmathlib.library"
  9. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  10.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  11.     call notify(1,"!Can't find "MATHLIB)
  12.     exit
  13.     END
  14.  
  15. sysnam = 'Spline Cage'
  16. filnam = 'T:cage.state'
  17. version = 'Spline Cage v1.0'
  18.  
  19. /* Setup state.  Read stored one, if any.
  20.  */
  21. seg = 2
  22. sid = 8
  23. top = 1
  24. bot = -1
  25. cen = 0 0 0
  26. rad = 1 1 1
  27. axis= 2
  28.  
  29. if (exists(filnam)) then do
  30.     if (~open(state, filnam, 'R')) then break
  31.     if (readln(state) ~= version) then break
  32.     parse value readln(state) with seg sid top bot axis .
  33.     cen = readln(state)
  34.     rad = readln(state)
  35.     call close state
  36. end
  37.  
  38. call req_begin sysnam
  39.  
  40. id_ax  = req_addcontrol("Axis", 'c', 'X Y Z')
  41. id_sid = req_addcontrol("Sides", 'n')
  42. id_seg = req_addcontrol("Segments", 'n')
  43. id_top = req_addcontrol("Top", 'n', 1)
  44. id_bot = req_addcontrol("Bottom", 'n', 1)
  45. id_rad = req_addcontrol("Radius", 'v', 1)
  46. id_cen = req_addcontrol("Center", 'v', 1)
  47.  
  48. call req_setval id_ax,  axis
  49. call req_setval id_sid, sid, 8
  50. call req_setval id_seg, seg, 2
  51. call req_setval id_top, top, 1
  52. call req_setval id_bot, bot, -1
  53. call req_setval id_rad, rad, 1
  54. call req_setval id_cen, cen, 0
  55.  
  56. if (~req_post()) then do
  57.     call req_end
  58.     exit
  59. end
  60.  
  61. axis= req_getval(id_ax)
  62. seg = req_getval(id_seg) % 1
  63. sid = req_getval(id_sid) % 1
  64. top = req_getval(id_top)
  65. bot = req_getval(id_bot)
  66. cen = req_getval(id_cen)
  67. rad = req_getval(id_rad)
  68. if (seg < 1) then seg = 1
  69. if (sid < 3) then sid = 3
  70.  
  71. call req_end
  72.  
  73. /* Save state now, in case something fails.
  74.  */
  75. if (open(state, filnam, 'W')) then do
  76.     call writeln state, version
  77.     call writeln state, seg sid top bot axis
  78.     call writeln state, cen
  79.     call writeln state, rad
  80.     call close state
  81. end
  82.  
  83. /* Prep
  84.  */
  85. rx = word(rad,1)
  86. ry = word(rad,2)
  87. cx = word(cen,1)
  88. cy = word(cen,2)
  89. totalpoints = sid * (seg+1)
  90. totalcurves = seg + 1 + sid
  91.  
  92. call add_begin
  93. call meter_begin totalpoints + totalcurves, sysnam
  94.  
  95. /* Create point rings.
  96.  */
  97. do i=0 to seg
  98.     z = (top - bot) * i / seg + bot
  99.     vl = ""
  100.     do j=0 to sid-1
  101.     a = 6.2832 * j / sid
  102.     x = rx * sin(a) + cx
  103.     y = ry * cos(a) + cy
  104.     vl = vl add_point(x y z)
  105.     call meter_step
  106.     end
  107.     vl = subword(vl,sid,1) vl subword(vl,1,2)
  108.     call add_curve vl, 'se'
  109.     call meter_step
  110. end
  111.  
  112. do i = 1 to sid
  113.     vl = ""
  114.     do j = 0 to seg
  115.     vl = vl i+j*sid
  116.     end
  117.     call add_curve vl
  118.     call meter_step
  119. end
  120. call meter_end
  121. call add_end
  122.  
  123. exit
  124.  
  125. syntax:
  126. error:
  127.     t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
  128.     exit
  129.